package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerCertification;
import com.shrcl.engineerprocess.domain.EngineerCertificationDAO;
import com.shrcl.engineerprocess.domain.UpdateEngineerCertificationTask;
import com.shrcl.engineerprocess.domain.impl.EngineerCertificationImpl;
import com.shrcl.engineerprocess.domain.impl.EngineerNotitableTaskExtensionImpl;
import com.shrcl.engineerprocess.domain.proxy.UpdateEngineerCertificationTaskProxy;
import edu.fudan.langlab.domain.task.TSKTask;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("UPDATEENGINEERCERTIFICATIONTASK_TYPE")
public class UpdateEngineerCertificationTaskImpl extends EngineerNotitableTaskExtensionImpl implements UpdateEngineerCertificationTask {
  public UpdateEngineerCertificationTaskImpl() {
    super();
  }
  
  @JoinColumn(name = "engineerCertification_id")
  @ManyToOne(targetEntity = EngineerCertificationImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private EngineerCertification engineerCertification;
  
  public EngineerCertification getEngineerCertification() {
    return this.engineerCertification;
  }
  
  public UpdateEngineerCertificationTask setEngineerCertification(final EngineerCertification engineerCertification) {
    this.engineerCertification = engineerCertification;
    return this;			
    
  }
  
  public String getTaskType() {
    return "UpdateEngineerCertificationTask";
  }
  
  public String getTaskName() {
    return "\u671F\u6EE1\u6362\u8BC1";
  }
  
  public String getTaskDescription() {
    String _plus = ("\u5DE5\u7A0B\u5E08" + "[");
    Engineer _engineer = this.engineerCertification.getEngineer();
    String _name = _engineer.getName();
    String _plus_1 = (_plus + _name);
    String _plus_2 = (_plus_1 + "]");
    String _plus_3 = (_plus_2 + "\u8BC1\u4E66\u5230\u671F\u66F4\u65B0");
    return _plus_3;
  }
  
  public void performCommit() {
    this.engineerCertification.commit();
    TSKTask _task = this.getTask();
    _task.finish();
  }
  
  public void performRenew() {
    this.engineerCertification.forceClosed();
    BeanFactory _beanFactory = this.getBeanFactory();
    final EngineerCertificationDAO dao = _beanFactory.<EngineerCertificationDAO>getBean(EngineerCertificationDAO.class);
    EngineerCertification _renewEngineerCert = dao.renewEngineerCert(this.engineerCertification);
    this.engineerCertification = _renewEngineerCert;
  }
  
  public void performReject() {
    TSKTask _task = this.getTask();
    _task.finish();
  }
  
  public static UpdateEngineerCertificationTask create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.UpdateEngineerCertificationTask updateEngineerCertificationTask = new com.shrcl.engineerprocess.domain.impl.UpdateEngineerCertificationTaskImpl(
    );
    objectFactory.create(updateEngineerCertificationTask);
    return updateEngineerCertificationTask;			
    
  }
  
  public static UpdateEngineerCertificationTask createUpdateEngineerCertificationTaskImpl(final IObjectFactory objectFactory, final Procedure1<UpdateEngineerCertificationTask> init) {
    com.shrcl.engineerprocess.domain.UpdateEngineerCertificationTask updateEngineerCertificationTask = new com.shrcl.engineerprocess.domain.impl.UpdateEngineerCertificationTaskImpl(
    );
    objectFactory.create(updateEngineerCertificationTask);
    init.apply(updateEngineerCertificationTask);
    
    return updateEngineerCertificationTask;			
    
  }
  
  public UpdateEngineerCertificationTaskProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.UpdateEngineerCertificationTaskProxy proxy = new com.shrcl.engineerprocess.domain.proxy.UpdateEngineerCertificationTaskProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
